package org.maxgroundstation.groundstation;

import java.io.File;
import java.io.IOException;

/**
 * Main class for starting MAX ground station application by double-clicking
 * on the MaxGroundStationStarter jar file.  Not used by other starter 
 * applications.
 * @author Scott Davis
 * 
 * Copyright (C) 2010  Scott Davis
 * 
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 * 
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */
public class GroundStationStarter {

    /**
     * Main method for starting application.
     * @param args
     */
    public static void main(String[] args) {
        try {
            StringBuffer command = new StringBuffer();
            
            String javaHome = System.getenv("JAVA_HOME");
            if (javaHome != null) {
                if (javaHome.contains(" ")) javaHome = "\"" + javaHome;
                command.append(javaHome + File.separator + "bin" + File.separator + "java");
                if (javaHome.contains(" ")) command.append("\"");
            }
            else command.append("java");
            
            command.append(" -Djava.library.path=./lib");
            command.append(" -cp MaxGroundStation.jar");
            command.append(" org.maxgroundstation.groundstation.GroundStation");
            command.append(" 0.0.0.0");
            command.append(" resources/metaData.txt");
            
            String commandStr = command.toString();
            System.out.println("Command: " + commandStr);
            Runtime.getRuntime().exec(commandStr);
        }
        catch(IOException e) {
            System.out.println("Error starting GroundStation");
            e.printStackTrace(System.err);
        }
    }
}